﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectEuler
{
    class Program
    {
        static void Main(string[] args)
        {
            string strNum = "";
            string strParam;
            string[] strArParam;
            Int64[] i64Param;
            Problem p = null;
            string res;
            while (strNum != "0")
            {
                Console.WriteLine("Enter the number of problem to solve (0 to exit):");
                strNum = Console.ReadLine().Trim();
                try
                {
                    p = (Problem)Activator.CreateInstance(Type.GetType("ProjectEuler.p" + strNum));
                }
                catch
                {
                    Console.WriteLine("The problem is not implemented");
                    continue;
                }
                Console.WriteLine(p.strParamPrompt);
                strParam = Console.ReadLine().Trim();
                strArParam = strParam.Split(new Char[] { }, StringSplitOptions.RemoveEmptyEntries);
                int i = 0;
                i64Param = null;
                if (strArParam.Length > 0)
                    i64Param = new Int64[strArParam.Length];
                foreach (string str in strArParam)
                {
                    i64Param[i++] = Convert.ToInt64(str);
                }
                try
                {
                    res = p.Solve(i64Param);
                }
                catch (Exception Exception)
                {
                    Console.WriteLine("The solution generated exception:{0}", Exception);
                    continue;

                }
                Console.WriteLine("Problem {0} solved in {1}. Result is:", strNum, p.runTime);
                Console.WriteLine(res);
            }
        }
    }
}
